//
//  AXFMessageController.m
//  AXFEightGroup
//
//  Created by hgj on 2016/12/27.
//  Copyright © 2016年 ya. All rights reserved.
//

#import "AXFMessageController.h"
#import "AXFUserInfoController.h"
#import "AXFSystemInfoController.h"

@interface AXFMessageController ()

@property (nonatomic, weak) UISegmentedControl *segment;
@property (nonatomic, strong) UIView *userView;
@property (nonatomic, strong) UIView *systemView;

@end

@implementation AXFMessageController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupSegmentedControl];
}

- (void)setupSegmentedControl {
    
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"系统消息",@"用户消息"]];
    
    for (int i = 0; i < segment.numberOfSegments; i++) {
        [segment setWidth:80 forSegmentAtIndex:i];
    }
    
    segment.selectedSegmentIndex = 0;
    
    [self addSubView];
    
    [segment addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged];
    
    self.navigationItem.titleView = segment;
    
    _segment = segment;
    
    [self.view bringSubviewToFront:self.userView];
}

- (void)addSubView{
    
    // 系统消息控制器
    AXFUserInfoController *tableVC = [AXFUserInfoController new];
    
    [self addChildViewController:tableVC];
    [self.view addSubview:tableVC.view];
    [tableVC didMoveToParentViewController:self];
    
    [tableVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(44, 0, 0, 0));
    }];
    
    _userView = tableVC.view;
    
    // 用户消息控制器
    AXFSystemInfoController *systemVC = [AXFSystemInfoController new];
    
    [self addChildViewController:systemVC];
    [self.view addSubview:systemVC.view];
    [systemVC didMoveToParentViewController:self];
    
    [systemVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(64, 0, 0, 0));
    }];
    
    _systemView = systemVC.view;
}

- (void)segmentClick:(UISegmentedControl *)segment {
    
    switch (segment.selectedSegmentIndex) {
        case 0:
            [self.view bringSubviewToFront:self.userView];
            break;
        case 1:
            [self.view bringSubviewToFront:self.systemView];
            break;
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

@end
